-- tests scene
local layer = nil
    
local function GetSkilllvID(skid, lv)
    return skid*IndexSkillTag+lv
end
local function initWithLayer(stage)
    -------- ui
    -- 背景
    local _bgSpr = nil
    _bgSpr = CCSprite:createWithSpriteFrameName(s_Space_bg)
    _bgSpr:setPosition(gdccp(DWinSizeWidth/2, DWinSizeHeight/2))
    layer:addChild(_bgSpr)
    _bgSpr = CCSprite:createWithSpriteFrameName(s_Space_bgHead)
    _bgSpr:setPosition(gdccp(DWinSizeWidth/2, 960-32))
    layer:addChild(_bgSpr, 9)
    
    --显示魂力值
    local _lblSoul = CCLabelTTF:create(table.concat({"魂力:",GetSoulPower()}), "Arial",FontSize)
    _lblSoul:setPosition(gdccp(200, 50))
    layer:addChild(_lblSoul)
    
    
    
    local _tableSkillIcon = {}
    -- 不同的职业用不同的页面切换
    _layerRole = CCLayer:create()
    _mainMenu = CCMenu:create()
    
    -- 按钮回调函数
    _menuCallback = function (tag)
    end
    
    
    
    
    
    _layerRole:addChild(_mainMenu,1)
    layer:addChild(_layerRole, 5)
    
    -- 显示模型
    require "lua/ui_fight"
    -- 战场layer
    local _layerBattle = BattleField:new()
    _layerRole:addChild(_layerBattle.layer, 4)
    
    local roleTable = {}
    
    local index = 0
    local bpx = 100
    local bpy = DWinSizeHeight - 200
    local inv = 220
    -- 创建职业面板
    local function createRolePanel(role)
        --- 加载模型
        local model = _layerBattle:createRole(role, gdccp(bpx + inv * (index%3), bpy - inv * math.floor(index/3)), false)
        model.model:setScale(1.0)
        model._iTeam = 1
        
        table.insert(roleTable, model)
    end
    
    table.foreach(Datas_Role, function(k,info)
        createRolePanel(k)
        index = index + 1
    end)
    
    local function onTouchBegin(x, y)
        --return 1
    end
    
    local function onTouchMoved(x, y)
    end
    
    local function onTouchEnded(x, y)
    end

    -- 触摸操作
    local function onTouch(eventType, x, y)
        if eventType == CCTOUCHBEGAN then
            return onTouchBegin(x, y)
        elseif eventType == CCTOUCHMOVED then
            return onTouchMoved(x, y)
        elseif eventType == CCTOUCHENDED then
            return onTouchEnded(x, y)
        end
    end
    
    layer:setTouchEnabled(true)
    layer:registerScriptTouchHandler(onTouch)
    
    
    -----------------   update
    local changeAnim = 5
    local lchange = 1
    local actlist = {"skill","stand","attack","hurt","attack2"}
    local actidx = 1
    local function update(dt)
        _layerBattle:update(dt)
        
        lchange = lchange - dt
        if lchange <= 0 then
            table.foreach(roleTable, function(k,model)
                print(k,actlist[actidx])
                model.anim:getAnimation():playTo(actlist[actidx])
                print("__",k)
            end)
            actidx = actidx + 1
            if actidx > #actlist then
                actidx = 1
            end
            lchange = changeAnim
        end
    end
    ---暂停游戏
    local _joinGame = false
    local _gameRun = false
    local _baseLayer_entry = nil
    local function _onGameRun()
        if not _gameRun then
            _baseLayer_entry = CCDirector:sharedDirector():getScheduler():scheduleScriptFunc(update,2.0/60.0,false)
            _gameRun = true
        else
            if _baseLayer_entry ~= nil then
                CCDirector:sharedDirector():getScheduler():unscheduleScriptEntry(_baseLayer_entry)
            end
            _baseLayer_entry = nil
            _gameRun = false
        end
    end
    
    local function SpriteEase_onEnterOrExit(tag,tag2)
        if not _joinGame then
            _joinGame = true
            _gameRun = false
        else
            _joinGame = false
            _gameRun = true
        end
        _onGameRun()
    end
    -- 注册进入/退出事件
    layer:registerScriptHandler(SpriteEase_onEnterOrExit)

    return layer
end

--------------------------------
-- Click And Move Test
--------------------------------
function Create_RoleShow_Scene(stage)
    local scene = CCScene:create()
    layer = CCLayer:create()

    initWithLayer(stage)

    scene:addChild(layer)
    scene:addChild(CreateBackMenuItem())

    GameReplaceScne(scene, UI_RoleShow)
    
    return scene, UI_RoleShow
end
